﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lswweb.IDAL;
using Lswweb.Model;
using Lswweb.Domain;

namespace Lswweb.Domain
{
    public class Messages
    {
        private static IMessages dal = DALFactory.CreateMessagesDAL();

        public static MessageInfo GetModel(int id)
        {
            return dal.GetModel(id);
        }

        public static void Insert(MessageInfo info)
        {
            if (info == null)
            {
                SiteContext.RenderMessage(ExceptionType.UnknownError);
                return;
            }

            if (dal.Insert(info) > 0)
                SiteContext.RenderMessage(ExceptionType.HandleSuccess);
            else
                SiteContext.RenderMessage(ExceptionType.UnknownError);
        }

        public static void Delete(int id)
        {
            if (id <= 0)
            {
                SiteContext.RenderMessage(ExceptionType.UnknownError);
                return;
            }

            if (dal.Delete(id))
                SiteContext.RenderMessage(ExceptionType.HandleSuccess);
            else
                SiteContext.RenderMessage(ExceptionType.UnknownError);
        }

        public static void IsRead()
        {
            dal.UpdateIsRead(SiteContext.Current.Id);
        }

        public static IList<MessageInfo> GetModels(bool isRead,int pageSize,int pageIndex,out int totalRecord)
        {
            return dal.GetModels(isRead,pageSize,pageIndex,out totalRecord);
        }
    }
}
